var express=require('express');
const axios = require('axios');
var router=express.Router();

router.get('/',function(req,res,next){
    // res.send("修改个人信息页面");
    res.render('app/personList');
})

/**
 * @api {post} /admin/personList/updata 更新用户信息
 * @apiName 用户注册
 * @apiGroup User
 *
 * @apiParam {String} nickname 昵称.
 * @apiParam {String} sex 性别.
 * @apiParam {String} password 密码.
 * @apiParam {String} personInformation 用户简介.
 *@apiParam {String} file 头像.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */
router.post('/updata', (req, res) => {
    let { password,sex,nickname,file,personInformation } = req.body
    // let mobliePhone1 = mobliePhone;
    var config = {
            method: 'post',
            baseURL: 'http://wlgzs.frp.wkyhky.site',
            url: '/tb-user/updata',
            params: {
                id:2,
                mobliePhone: 18568523104,
                password: password,
                sex:sex,
                nickname:nickname,
                file:file,
                personInformation:personInformation
            },
            headers: {//指定响应头
                "Content-Type": "application/json;charset=utf-8",
                "Accept": "application/json"
            }
        }
        axios(config)
            .then(function (response) {
                if (response.data.code=='success'){
                    res.redirect('/admin/personal');//成功后回到个人中心页面
                }else{
                    res.redirect('/homepage');//成功后回到zhu页面
                }
            })
            .catch(function (error) {
                console.log(error);
                console.log("失败")
            });

})

module.exports=router;
